package com.wl.api.dto.base;

import java.util.Date;

import com.wl.api.common.utils.ObjectUtil;
import com.wl.api.common.utils.StringUtil;
import com.wl.api.dto.system.OmsProductServiceDTO;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class PaginationConst {
	
	public Integer page =1;
	
	public  Integer pageSize =20;
	
	private Date createTime;

	private Long createUserId;
	
	private String createUser;
	
	private Date updateTime;

	private String updateUser;
	
	private Long updateUserId;
	
	private String startTime; //yyyy-MM-dd
	private String endTime;//yyyy-MM-dd
	
	public Integer getPage(){
		return (this.page == null || this.page < 1)? 1: this.page;
	}
	
	public Integer getPageSize() {
		return (this.pageSize == null || this.pageSize<5 || this.pageSize > 50)? 20: this.pageSize;
	}
	
	public PaginationConst buildCreateMsg(Long userId, String createUser) {
		this.createUserId = userId;
		this.createTime = new Date();
		this.createUser = createUser;
		return this;
	}
	public PaginationConst buildCreateMsg(Long userId) {
		this.createUserId = userId;
		this.createTime = new Date();
		return this;
	}
	public PaginationConst buildUpdateMsg(String username) {
		this.updateUser = username;
		this.updateTime = new Date();
		return this;
	}
	public PaginationConst buildUpdateMsg(Long updateUserId, String username) {
		this.updateUser = username;
		this.updateTime = new Date();
		this.updateUserId = updateUserId;
		return this;
	}
	
	public PaginationConst buildPage(Integer page, Integer pageSize) {
		this.page = ObjectUtil.isEmpty(page) ? 1 : page;
		this.pageSize = ObjectUtil.isEmpty(pageSize) ? 20: pageSize;
		return this;
	}
	public String getStartTime() {
		
		return StringUtil.isEmpty(startTime)? null: (startTime + " 00:00:00");
	}
	
	public String getEndTime() {
		
		return StringUtil.isEmpty(endTime)? null: (endTime + " 23:59:59");
	}
	
	public PaginationConst buildStartTime(String startTime) {
		this.startTime = StringUtil.isEmpty(startTime)? null: (startTime + " 00:00:00");
		return this;
	}
	public PaginationConst buildEndTime(String endTime) {
		this.endTime = StringUtil.isEmpty(endTime)? null: (endTime + " 23:59:59");
		return this;
	}
}
